package com.shop.service.impl;

import com.shop.mapper.ILoginMapper;
import com.shop.pojo.CommonResult;
import com.shop.service.ILoginService;
import com.shop.utils.TokenUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class LoginServiceImpl implements ILoginService {
    @Resource
    private ILoginMapper loginMapper;

    @Override
    public CommonResult<Map> login(String username, String password) {
        Integer rows = loginMapper.login(username, password);
        Map<String, String> data = new HashMap<>();
        if (rows == 1) {
            data.put("token", TokenUtil.getToken(username, password));
            return new CommonResult<>(200, "success", data);
        }
        return new CommonResult<>(400, "账号或密码错误", data);
    }
}
